package com.wonders.service.impl;

import com.wonders.entity.UserInfo;
import com.wonders.exception.CustomerException;
import com.wonders.mapper.UserInfoMapper;
import com.wonders.service.UserInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author huangweiyue
 * @version v1.0
 * @task
 * @description
 * @date Created in 2021-03-16
 * @modifiedBy
 */
@Slf4j
@Service
public class UserInfoServiceImpl implements UserInfoService {
    @Autowired
    private UserInfoMapper userInfoMapper;


    @Transactional(rollbackFor = Exception.class)
    @Override
    public void insertOne() throws CustomerException {
        UserInfo userInfo = UserInfo.builder().name("张狗蛋").passWord("123456").salt("salt").state(new Byte("1")).userName("张三").build();
        int num = userInfoMapper.insert(userInfo);
        //默认情况下，也就是当 @Transactional不填充任何参数的情况下，只有运行时异常事务才会回滚
        throw new RuntimeException("运行时异常");
        //默认情况下，非运行异常，不会回滚事务，所以我们通常都显示的声明rollbackFor = Exception.class,此时不管何种类型异常都会回滚事务
        //throw new CustomerException("运行时异常");
    }
}
